package cl.lexer.validator;

import cl.lexer.Token;
import cl.lexer.TokenType;

public class IdentifierValidator implements TokenValidator {

    @Override
    public TokenType getType() {
        return TokenType.IDENTIFIER;
    }

    @Override
    public boolean isValid(String value) {
        if(value.isEmpty()) {
            return false;
        }
        
        if(value.charAt(0) >= '0' && value.charAt(0) <= '9') {
            return false;
        }
        
        for(char c : value.toCharArray()) {
            if((c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && 
                    (c < '0' || c > '9') && c != '_') {
                return false;
            }
        }
        
        return true;
    }

    @Override
    public boolean possiblyValid(String value) {
        return isValid(value);
    }

    @Override
    public Token generateToken(String value) {
        return new Token(TokenType.IDENTIFIER, value);
    }

}
